{% extends "base.html" %}

{% block title %}班级管理 - 学生成绩管理系统{% endblock %}

{% block extra_css %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/common.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/admin/class.css') }}">
{% endblock %}

{% block content %}
<div class="class-wrapper">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2 class="page-title">
            <i class="fas fa-users text-primary"></i>
            班级管理
        </h2>
        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addClassModal">
            <i class="fas fa-plus"></i> 添加班级
        </button>
    </div>

    <div class="card mb-4">
        <div class="card-body">
            <div class="row">
                <div class="col-md-2">
                    <div class="input-group">
                        <span class="input-group-text"><i class="fas fa-search"></i></span>
                        <input type="text" class="form-control" id="searchInput" placeholder="搜索班级名称...">
                    </div>
                </div>
                <div class="col-md-2">
                    <select class="form-select" id="gradeFilter">
                        <option value="">所有年级</option>
                        <option value="2015">2015级</option>
                        <option value="2016">2016级</option>
                        <option value="2017">2017级</option>
                        <option value="2018">2018级</option>
                        <option value="2019">2019级</option>
                        <option value="2020">2020级</option>
                        <option value="2021">2021级</option>
                        <option value="2022">2022级</option>
                        <option value="2023">2023级</option>
                        <option value="2024">2024级</option>
                        <option value="2025">2025级</option>
                    </select>
                </div>
                <div class="col-md-1">
                    <button type="button" class="btn btn-outline-secondary w-100" onclick="resetFilters()">
                        <i class="fas fa-redo"></i> 重置
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0">
                <i class="fas fa-list"></i> 班级列表
                <span class="badge bg-primary ms-2" id="listCount">0</span>
            </h5>
        </div>
        <div class="card-body">
            <div id="loadingSpinner" class="text-center py-4">
                <div class="spinner-border text-primary" role="status">
                    <span class="visually-hidden">加载中...</span>
                </div>
                <p class="mt-2 text-muted">正在加载班级数据...</p>
            </div>

            <div class="table-responsive" id="classTableContainer" style="display: none;">
                <table class="table table-hover" id="classTable">
                    <thead class="table-light">
                        <tr>
                            <th>班级ID</th>
                            <th>班级名称</th>
                            <th>年级</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="classTableBody">
                    </tbody>
                </table>
            </div>

            <div id="emptyState" class="text-center py-5" style="display: none;">
                <i class="fas fa-users fa-3x text-muted mb-3"></i>
                <h5 class="text-muted">暂无班级数据</h5>
                <p class="text-muted">点击上方"添加班级"按钮开始添加班级</p>
            </div>
        </div>
    </div>

    <div aria-label="班级分页" class="mt-4">
        <ul class="pagination justify-content-center" id="pagination">
        </ul>
    </div>
</div>

<div class="modal fade" id="addClassModal" tabindex="-1" aria-labelledby="addClassModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="addClassModalLabel">
                    <i class="fas fa-plus text-primary"></i> 添加班级
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form id="addClassForm">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="addClassName" class="form-label">班级名称 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="addClassName" name="name" required
                                       placeholder="如：（1）班" maxlength="100">
                                <div class="invalid-feedback">请输入班级名称</div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="addClassGrade" class="form-label">年级 <span class="text-danger">*</span></label>
                                <select class="form-select" id="addClassGrade" name="grade" required>
                                    <option value="">请选择年级</option>
                                    <option value="2015">2015级</option>
                                    <option value="2016">2016级</option>
                                    <option value="2017">2017级</option>
                                    <option value="2018">2018级</option>
                                    <option value="2019">2019级</option>
                                    <option value="2020">2020级</option>
                                    <option value="2021">2021级</option>
                                    <option value="2022">2022级</option>
                                    <option value="2023">2023级</option>
                                    <option value="2024">2024级</option>
                                    <option value="2025">2025级</option>
                                </select>
                                <div class="invalid-feedback">请选择年级</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-save"></i> 保存班级
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="editClassModal" tabindex="-1" aria-labelledby="editClassModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editClassModalLabel">
                    <i class="fas fa-edit text-warning"></i> 编辑班级
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form id="editClassForm">
                <div class="modal-body">
                    <input type="hidden" id="editClassId" name="id">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="editClassName" class="form-label">班级名称 <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="editClassName" name="name" required
                                       placeholder="如：（1）班" maxlength="100">
                                <div class="invalid-feedback">请输入班级名称</div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="editClassGrade" class="form-label">年级 <span class="text-danger">*</span></label>
                                <select class="form-select" id="editClassGrade" name="grade" required>
                                    <option value="">请选择年级</option>
                                    <option value="2015">2015级</option>
                                    <option value="2016">2016级</option>
                                    <option value="2017">2017级</option>
                                    <option value="2018">2018级</option>
                                    <option value="2019">2019级</option>
                                    <option value="2020">2020级</option>
                                    <option value="2021">2021级</option>
                                    <option value="2022">2022级</option>
                                    <option value="2023">2023级</option>
                                    <option value="2024">2024级</option>
                                    <option value="2025">2025级</option>
                                </select>
                                <div class="invalid-feedback">请选择年级</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-warning">
                        <i class="fas fa-save"></i> 更新班级
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="deleteClassModal" tabindex="-1" aria-labelledby="deleteClassModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="deleteClassModalLabel">
                    <i class="fas fa-exclamation-triangle text-danger"></i> 确认删除
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <p>您确定要删除班级 <strong id="deleteClassInfo"></strong> 吗？</p>
                <div class="alert alert-warning">
                    <i class="fas fa-exclamation-triangle"></i>
                    <strong>警告：</strong>删除班级将同时删除该班级的所有学生记录和成绩记录，此操作不可撤销！
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-danger" id="confirmDeleteBtn">
                    <i class="fas fa-trash"></i> 确认删除
                </button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script src="{{ url_for('static', filename='js/admin/class.js') }}"></script>
{% endblock %}